package com.rftennis.web.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.rftennis.dto.CustomerContext;
import com.rftennis.dto.JSONResponce;
import com.rftennis.service.CustomerService;

@Controller
public class UserController {
	@Autowired
	CustomerService service;

	@PostMapping("/login.do")
	public @ResponseBody JSONResponce login(String account, String password, HttpSession session) throws Exception {
		CustomerContext c = service.login(account, password);
		session.setAttribute(CustomerContext.class.getName(), c);
		return JSONResponce.ok(c);
	}

	@GetMapping("/logout.do")
	public String logout(HttpSession session) throws Exception {
		session.invalidate();
		return "redirect:/login.html";
	}


}